import re


class StrTools(object):

    @staticmethod
    def strip_symbol(string):
        # 1.去除文本中的标签
        ele_pattern = re.compile(r'<.*?>', re.S)
        string = re.sub(ele_pattern, "", string)
        string = string.strip()

        return string

    @staticmethod
    def process_come_from(string):
        """处理来自客户端"""
        if '来自' in string:
            pattern = re.compile(r'<span class="tail-info.*?>(.*?)</span.*?<sp.*?>(.*?)</sp.*?<sp.*?>(.*?)<', re.S)

            res = re.findall(pattern, string)
            # 取出小元组
            info = res[0]
            come_from = StrTools.strip_symbol(info[0])
            # 返回 来自客户端  楼层  日期时间
            return come_from, info[1], info[2]
        else:
            pattern = re.compile(r'<span class="tail-info.*?>(.*?)</span.*?<sp.*?>(.*?)</sp', re.S)

            res = re.findall(pattern, string)
            info = res[0]

            # 返回 来自客户端  楼层  日期时间
            return '未知客户端', info[0], info[1]